//
// Created by liushuai on 12/30/19.
//
#include "mergeLink.hpp"

Node *mergeLink(Node *l1, Node *l2) {
    Node *prenode = new Node(-1);
    Node *head = prenode;
    while (l1 != nullptr && l2 != nullptr) {
        if (l1->value <= l2->value) {
            prenode->next = l1;
            l1 = l1->next;
        } else {
            prenode->next = l2;
            l2 = l2->next;
        }
        prenode = prenode->next;
    }
    prenode->next = l1 == nullptr ? l2 : l1;
    return head->next;
}
